package com.yc.rpc.core;

import com.yc.rpc.core.annotation.YcRpc;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.core.type.filter.AnnotationTypeFilter;

import java.util.Set;

public class YcRpcClasssPathBeanDefinitionScanner extends ClassPathBeanDefinitionScanner {

      public YcRpcClasssPathBeanDefinitionScanner(BeanDefinitionRegistry registry,
                                                  boolean useDefaultFilters) {
          super(registry, useDefaultFilters);
      }
  
      /**
       * @Author haien
       * @Description 注册条件过滤器，将@Mapper注解加入允许扫描的过滤器中，
       * 如果加入排除扫描的过滤器集合excludeFilter中，则不会扫描
       * @Date 2019/6/11
       * @Param []
       * @return void
       **/
      protected void registerFilters(){
          addIncludeFilter(new AnnotationTypeFilter(YcRpc.class));
      }
  
      @Override
      protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
          return super.doScan(basePackages);
      }

    @Override
    protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
        return beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().isIndependent();
    }

}